package edu.uci.ics.ai.maze.controllers;

import edu.uci.ics.ai.maze.models.Vertex;
import edu.uci.ics.ai.maze.models.Polygon;
import edu.uci.ics.ai.maze.models.GameModel;
import edu.uci.ics.ai.maze.models.SearchAlgorithm;
import java.util.List;

/**
 * Provides a means by which a
 * {@link edu.uci.ics.ai.maze.models.SearchAlgorithm} implementer can safely
 * access maze data.
 */
public class SearchContext {

  private final GameModel model;

  public SearchContext(GameModel model) {
    this.model = model;
  }

  /**
   * Returns true if there is a clear path between the two vertices v1 & v2
   */
  public boolean isVisible(final Vertex v1, final Vertex v2) {
    return getModel().getMaze().isVisible(v1, v2);
  }

  /**
   * Returns the start vertex.
   */
  public Vertex getStart() {
    return getModel().getMaze().getStart();
  }

  /**
   * Returns the goal vertex.
   */
  public Vertex getGoal() {
    return getModel().getMaze().getGoal();
  }

  /**
   * Returns the total number of vertices in the maze.
   */
  public int getVertexCount() {
    return getVertices().size();
  }

  /**
   * Returns the list of all the vertices of all the Polygons in the Maze.
   *
   * @return the vertices of all the polygons in the Maze
   */
  public List<Vertex> getVertices() {
    return getModel().getMaze().getVertices();
  }

  /**
   * Returns the total number of polygons in the maze.
   *
   * @return the number of polygons in the maze
   */
  public int getPolygonCount() {
    return getModel().getMaze().getPolygons().size();
  }

  /**
   * Returns the list of Polygons in the Maze.
   *
   * @return polygons in the Maze
   */
  public List<Polygon> getPolygons() {
    return getModel().getMaze().getPolygons();
  }

  /**
   * Returns the GameModel.
   *
   * <p> This method is made available for testing only.
   *
   * @return the model
   */
  protected GameModel getModel() {
    return model;
  }

}
